/*
 * Copyright 2008 Zoundry LLC, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package org.zoundry.gaedt.core.models.application;

import test.org.zoundry.gaedt.core.ZGaeCoreTestCase;

/**
 * Test case for the gae application handler model.
 */
public class ZGaeHandlerModelTest extends ZGaeCoreTestCase
{
    /**
     * Tests the handler model.
     *
     * @throws Exception
     */
    public void testScriptHandlerModel() throws Exception
    {
        ZGaeScriptHandlerModel model = new ZGaeScriptHandlerModel();
        model.setUrl("/path");
        model.setScript("scriptName.py");
        model.setLogin(TZGaeHandlerLoginType.Required);

        assertEquals("/path", model.getUrl());
        assertEquals("scriptName.py", model.getScript());
        assertEquals(TZGaeHandlerLoginType.Required, model.getLogin());
    }

    /**
     * Tests the handler model.
     *
     * @throws Exception
     */
    public void testStaticDirectoryHandlerModel() throws Exception
    {
        ZGaeStaticDirectoryHandlerModel model = new ZGaeStaticDirectoryHandlerModel();
        model.setUrl("/path");
        model.setStaticDir("/staticDir");
        model.setLogin(TZGaeHandlerLoginType.Admin);
        model.setExpiration("7d");
        model.setMimeType("text/plain");

        assertEquals("/path", model.getUrl());
        assertEquals("/staticDir", model.getStaticDir());
        assertEquals(TZGaeHandlerLoginType.Admin, model.getLogin());
        assertEquals("7d", model.getExpiration());
        assertEquals("text/plain", model.getMimeType());
    }

    /**
     * Tests the handler model.
     *
     * @throws Exception
     */
    public void testStaticFilePatternHandlerModel() throws Exception
    {
        ZGaeStaticFilePatternHandlerModel model = new ZGaeStaticFilePatternHandlerModel();
        model.setUrl("/item-(.*?)/category-(.*)");
        model.setStaticFiles("archives/\\2/items/\\1");
        model.setLogin(TZGaeHandlerLoginType.Admin);
        model.setExpiration("7d");
        model.setMimeType("image/jpeg");
        model.setUpload("archives/(.*?)/items/(.*)");

        assertEquals("/item-(.*?)/category-(.*)", model.getUrl());
        assertEquals("archives/\\2/items/\\1", model.getStaticFiles());
        assertEquals(TZGaeHandlerLoginType.Admin, model.getLogin());
        assertEquals("7d", model.getExpiration());
        assertEquals("image/jpeg", model.getMimeType());
        assertEquals("archives/(.*?)/items/(.*)", model.getUpload());
    }
}
